﻿export default function updateState(state, data) {
    // data : { counts:{sent,receipt}, sent:{title,headers,rowset}, receipt:{title,headers,rowset} }
     // update counts and rowset
    var history = {
        sent: getCategory('sent', state, data),
        receipt: getCategory('receipt',state,data)
    }
    return { ...state, history }
}
function getCategory(categoryName, state, data) {
    var localCategory = state.history && state.history[categoryName];
    if (!localCategory) localCategory = {};

    var remoteCategory = data[categoryName];
    var { rowset } = remoteCategory;
    var {
        title = remoteCategory.title,
        headers = remoteCategory.headers,
        pageCount = data.counts[categoryName],
        currentPage = 0,
    } = localCategory;
    return { title, pageCount, currentPage, headers, rowset };
}